// pages/remark/index.js
import {
  getCriticismList,addCriticism
} from "../../utils/request/Api"
import Notify from '@vant/weapp/notify/notify'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    defaultImg:"https://img.yzcdn.cn/vant/cat.jpeg",
    message:'',
    item:null,
    platext:"听说留言的人会涨粉丝",
    marking:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log();
    const {marking} = options
   
    this.setData({
      marking
    })
   this.getremarkList()
  },

  getremarkList(){
    const obj = {
      markings:this.data.marking
    }
    getCriticismList(obj).then(res=>{
      if(res.code==200){
        this.setData({
          list:res.data.list
        })
      }
    })
  },
  onRightText(e){
    const {item} = e.currentTarget.dataset
    this.setData({
      item,
      platext:"回复"+item.user_name
    })
  },
  onClickText(){
    const {item,message,marking} = this.data
    const user = wx.getStorageSync('user').user_markings
    if(item==null){
      const obj = {
        criticism_parent:0,
        criticism_text:message,
        song_markings:marking,
        user_markings:user,
        date:this.getDate()
      }
      addCriticism(obj).then(res=>{
        if(res.code==200){
          Notify(res.message);
          this.setData({
            message:"",
            item:null
          })
        }
      })
    }else{
      const obj = {
        criticism_child:item.criticism_id,
        criticism_text:message,
        song_markings:marking,
        user_markings:user,
        date:this.getDate()
      }
      addCriticism(obj).then(res=>{
        if(res.code==200){
          Notify(res.message);
          this.setData({
            message:"",
            item:null
          })
        }
      })
    }
    this.getremarkList()
  },
  getDate(){
    let today = new Date();
let year = today.getFullYear();
let month = (today.getMonth() + 1).toString().padStart(2, '0');
let day = today.getDate().toString().padStart(2, '0');
let hour = today.getHours()
let min = today.getMinutes()>10?"0"+today.getMinutes():today.getMinutes()
g
let currentDate = year +"-"+ month + "-"+day+" "+hour+":"+min;
    return currentDate
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})